//用户信息存储
#pragma once
#include <string>
#include <cstddef> 
#include <boost/date_time/posix_time/posix_time.hpp>
#include <odb/nullable.hxx>
#include <odb/core.hxx>


namespace zzy_mims
{
    #pragma db object table("user")
    class User 
    {   
    public:
        User(){};
        //用户有两种注册方式
        //方式一 用户名+密码
        User(const std::string& user_id,const std::string& nickname,const std::string& password)
        :_user_id(user_id),_nickname(nickname),_password(password){};
        //方式二 手机号
        User(const std::string& user_id,const std::string& phone)
        :_user_id(user_id),_phone(phone),_nickname(user_id){};
        
        void user_id(const std::string& val){_user_id = val;};
        std::string user_id()
        {
            return _user_id;
        }

        void phone(const std::string& val){_phone = val;};
        std::string phone()
        {
            if(!_phone) return std::string();
            return *_phone;
        }

        void nickname(const std::string& val){_nickname = val;};
        std::string nickname()
        {
            if(!_nickname) return std::string();
            return *_nickname;
        }
        void password(const std::string& val){_password = val;};
        std::string password()
        {
            if(!_password) return std::string();
            return *_password;
        }
        
        void description(const std::string& val){_description = val;};
        std::string description()
        {
            if(!_description) return std::string();
            return *_description;
        }
        void avatar_id(const std::string& val){_avatar_id = val;};
        std::string avatar_id()
        {
            if(!_avatar_id) return std::string();
            return *_avatar_id;
        }

    private:
        friend class odb::access;

        #pragma db id auto
        unsigned long _id;

        #pragma db type("varchar(64)") index unique
        std::string _user_id;

        #pragma db type("varchar(64)") index unique
        odb::nullable<std::string> _phone;

        #pragma db type("varchar(64)") index unique 
        odb::nullable<std::string> _nickname;
        #pragma db type("varchar(64)")
        odb::nullable<std::string> _password;

        #pragma db type("varchar(64)")
        odb::nullable<std::string> _avatar_id;
        odb::nullable<std::string> _description;
    };
}